package com.liucc.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;

public class ListValueConstraintValidator implements ConstraintValidator<ShowStatusValid, Integer> {

    private Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(ShowStatusValid constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    /**
     * 判断校验值是否在【0，1】范围内
     * @param value 所要校验的值
     * @param context context in which the constraint is evaluated
     *
     * @return
     */
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        set.add(0);
        set.add(1);
        return set.contains(value);
    }
}
